{extend name="public:index"/} {block name="title"}{:sysconf('title')}{/block} {block name="static"}
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>{/block} {block name="content"}
<script type="text/javascript">
    function onBridgeReady(json) {
        WeixinJSBridge.invoke('getBrandWCPayRequest',json, function(res) {
            console.log(res)
            if (res.err_msg == "get_brand_wcpay_request:ok") {
                window.location.href = "{:url('Order/index')}";
            } else if (res.err_msg = "get_brand_wcpay_request:cancel") {
                layer.msg('支付已取消', {
                    icon: 5
                }, function() {
                    window.location.href = "{:url('Order/index')}";
                });
            } else {
                layer.msg('支付失败', {
                    icon: 5
                }, function() {
                    window.location.href = "{:url('Order/index')}";
                });
            }
        })
    }
    /*if (typeof WeixinJSBridge == "undefined"){
        if( document.addEventListener ){
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        }else if (document.attachEvent){
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    }else{
        onBridgeReady();
    }*/
</script>
<section class="ddzxbox">
    <div class="top">
        <p class="p1">
            <a href="{:url('Order/index')}"></a>
        </p>
        <p class="p2">支付中心</p>
        <p class="p3"><a href="{:url('Order/index')}">订单列表</a></p>
    </div>
    <div style="height:2rem;"></div>
    <div class="zongji">需支付：<em>{$info['pay_money']}元</em></div>
    <div class="zhifu">
        <dl>
            <dt>支付方式</dt>
            <dd class="dd2"><label class="label"><p class="p1"></p>
                <p class="p2">余额<em>余额支付</em></p>
                <p class="p3"><input name="payType" type="radio" value="0"/></p></label>
            </dd>
            <dd class="dd1"><label class="label"><p class="p1"></p>
                <p class="p2">微信支付<em>微信安全支付</em></p>
                <p class="p3"><input name="payType" type="radio" value="1"/></p></label>
            </dd>
            {if condition="($balance lt $info['pay_money']) && ($balance gt 0)"}
            <dd class="dd1"><label class="label"><p class="p1"></p>
                <p class="p2">佣金抵扣<em>余额 + 微信</em></p>
                <p class="p3"><input name="payType" type="radio" value="2"/></p></label>
            </dd>
            {/if}
        </dl>
    </div>
    <div class="submit"><input type="button" value="确认支付" onclick="paymoney('{$info['order_no']}')"></div>
</section>
<script type="text/javascript">
    $('.ddzxbox .zhifu dd .label').click(function() {
        $('.ddzxbox .zhifu dd .label .p3').removeClass('canp');
        $('.p3', this).addClass('canp');
    });

    function paymoney(orderNo) {
        var payType = $("input[type=radio]:checked").val();
        if (!payType) {
            layer.msg('请选择支付方式', {icon: 5});
            return;
        }
        if (payType == 0) {
            $.ajax({
                url: "{:url('Pay/balancePay')}",
                type: "POST",
                data: {'orderNo': orderNo},
                dataType: "JSON",
                success: function(data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {'icon': 6, time: 1000}, function() {
                            window.location.href = "{:url('Order/index')}";
                        });
                    } else {
                        layer.msg(data.msg, {'icon': 5});
                    }
                },
                error: function() {
                    layer.msg("网络延迟，发送失败", {icon: 5});
                }
            });
        } else if (payType == 1) {
            $.ajax({
                url: "{:url('Pay/wechatPay')}",
                type: "POST",
                data: {'orderNo': orderNo,'payMoney':"{$info['pay_money']}",'payType':1},
                dataType: "JSON",
                success: function(data) {
                    if (data.code == 0) {
                        onBridgeReady(data.data)
                    } else {
                        layer.msg(data.msg, {'icon': 5}, function() {
                            window.location.href = "{:url('Order/index')}";
                        });
                    }
                },
                error: function() {
                    layer.msg("网络延迟，发送失败", {icon: 5});
                }
            });
        } else if (payType == 2) {
            $.ajax({
                url: "{:url('Pay/balanceWechatPay')}",
                type: "POST",
                data: {'orderNo': orderNo, 'payMoney': "{$info['pay_money']}", 'payType': 2},
                dataType: "JSON",
                success: function (data) {
                    if (data.code == 0) {
                        onBridgeReady(data.data)
                    } else {
                        layer.msg(data.msg, {'icon': 5}, function() {
                            window.location.href = "{:url('Order/index')}";
                        });
                    }
                },
                error: function () {
                    layer.msg("网络延迟，发送失败", {icon: 5});
                }
            });
        }
    }
</script>
{/block}